//
//  IntroViewController.m
//  ProjectForA
//
//  Created by apple on 14/11/19.
//  Copyright (c) 2014年 hmengwei. All rights reserved.
//

#import "IntroViewController.h"
#import "DestinationCollectionViewCell.h"
#import "HeaderCollectionReusableView.h"
#import "ConnectModel.h"
#import "SmallViewController.h"
#import "UnmissViewController.h"
#import "DetailViewController.h"
#import "SubjectViewController.h"
@interface IntroViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end

@implementation IntroViewController

- (void)dealloc
{
    [_IntrArr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self createScroll];
    [self createCollectionView];
}


- (void)createScroll
{
    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [_scroll setContentSize:CGSizeMake(0, self.view.frame.size.width * 3)];
    [self.view addSubview:_scroll];
    
//    NSMutableDictionary *dic = [_IntrArr objectAtIndex:]
    //主图
    UIButton *mainImage = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 250)];
    [mainImage setBackgroundColor:[UIColor orangeColor]];
    [mainImage addTarget:self action:@selector(small:) forControlEvents:UIControlEventTouchUpInside];
    [_scroll addSubview:mainImage];
    //介绍底板
    self.aView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.width / 5 * 3, self.view.frame.size.width, self.view.frame.size.width * 2)];
    [_aView setBackgroundColor:[UIColor whiteColor]];
    [_aView.layer setCornerRadius:10];
    [_aView.layer setMasksToBounds:YES];
    [_scroll addSubview:_aView];
    //按钮
    UIButton *unmiss = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 5, 25, self.view.frame.size.width / 5, self.view.frame.size.width / 5)];
    [unmiss setBackgroundColor:[UIColor blueColor]];
    [unmiss addTarget:self action:@selector(unmiss:) forControlEvents:UIControlEventTouchUpInside];
    [_aView addSubview:unmiss];
    
    UILabel *unmiassTitle = [[UILabel alloc] initWithFrame:CGRectMake(unmiss.frame.size.width / 5, unmiss.frame.size.height / 5 * 3, unmiss.frame.size.width / 5 * 3, unmiss.frame.size.width / 4)];
    [unmiassTitle setBackgroundColor:[UIColor whiteColor]];
    [unmiss addSubview:unmiassTitle];
    
    UIButton *subject = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 5 * 3, 25, self.view.frame.size.width / 5, self.view.frame.size.width / 5)];
    [subject setBackgroundColor:[UIColor orangeColor]];
    [subject addTarget:self action:@selector(subject:) forControlEvents:UIControlEventTouchUpInside];
    [_aView addSubview:subject];
    
    UILabel *subTitle = [[UILabel alloc] initWithFrame:CGRectMake(subject.frame.size.width / 5, subject.frame.size.height / 5 * 3, subject.frame.size.width / 5 * 3, subject.frame.size.width / 4)];
    [subTitle setBackgroundColor:[UIColor whiteColor]];
    [subject addSubview:subTitle];
    
    
    //中间
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, _aView.frame.size.height / 6, self.view.frame.size.width, 40)];
    [title setBackgroundColor:[UIColor redColor]];
    [title setText:@"sdsdsds"];
    [title setTextAlignment:NSTextAlignmentCenter];
    [_aView addSubview:title];
}

- (void)small:(id)sender
{
    SmallViewController *small = [[SmallViewController alloc] init];
    [self.navigationController pushViewController:small animated:YES];
}

- (void)unmiss:(id)sender
{
    UnmissViewController *unmiss = [[UnmissViewController alloc] init];
    [self.navigationController pushViewController:unmiss animated:YES];
}

- (void)subject:(id)sender
{
    SubjectViewController *subject = [[SubjectViewController alloc] init];
    [self.navigationController pushViewController:subject animated:YES];
}

- (void)createCollectionView
{
    //布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    [layout setItemSize:CGSizeMake(self.view.frame.size.width / 2.2, self.view.frame.size.width / 2.2)];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
//    layout.sectionInset = UIEdgeInsetsMake(50, 10, 0, 10);

    
    self.collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, _aView.frame.size.height / 6 + 40, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
    [_collect setBackgroundColor:[UIColor whiteColor]];
    _collect.dataSource = self;
    _collect.delegate = self;
    [_collect registerClass:[DestinationCollectionViewCell class] forCellWithReuseIdentifier:@"Intr"];
    [_aView addSubview:_collect];
    [_collect release];
    [layout release];
}

//items
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 6;
    
}

//重用池
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DestinationCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Intr" forIndexPath:indexPath];
    
    return cell;
}



//跳转
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    DetailViewController *detail = [[DetailViewController alloc] init];
    [self.navigationController pushViewController:detail animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
